package com.hstx.demo.mqtt;

import com.hstx.demo.mqtt.component.SpringContextUtil;
import com.hstx.demo.mqtt.until.Log;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class UiTest extends Application {
    private Stage thisStage;

    @Override
    public void start(Stage rootStage) {
        try {
            thisStage = new Stage();
            thisStage.initOwner(rootStage);
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com.hstx.demo.mqtt.controller.xml/UiTestController.fxml"));
            fxmlLoader.setControllerFactory(param -> SpringContextUtil.getBean(param));

            thisStage.setScene(new Scene(fxmlLoader.load()));
            thisStage.setOnShown(event -> {
                fxmlLoader.getController();
            });
            thisStage.show();
        } catch (IOException e) {
            Log.error(getClass(), e, "失败：初始化应用失败，退出应用程序");
            System.exit(0);
        }
    }
}
